import React, { Component } from 'react'
import {Form, Icon, Input, Button , message } from 'antd'

import './login.less'

class Login extends Component {
    handleSubmit= e =>{
        e.preventDefault();
        this.props.form.validateFields((err, { username , password }) => {
            if (!err) {
                message.success('登录成功！')
                console.log('username',username)
                console.log('password',password)
            } else {
                message.error('登录失败！')
            }
        });
    }
    render() {
        const { getFieldDecorator } = this.props.form;
        return (
            <div className="login-view">
                <div className="login-form-box">
                <Form onSubmit={this.handleSubmit} className="login-form">
                    <Form.Item>
                    {getFieldDecorator('username', {
                        rules: [{ required: true, message: '请输入用户名!' }],
                    })(
                        <Input
                            prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
                            placeholder="用户名"
                        />,
                    )}
                    </Form.Item>
                    <Form.Item>
                    {getFieldDecorator('password', {
                        rules: [{ required: true, message: '请输入密码!' }],
                    })(
                        <Input
                            prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />}
                            type="password"
                            placeholder="密码"
                        />,
                    )}
                    </Form.Item>
                    <Form.Item>
                    <Button type="primary" htmlType="submit" className="login-form-button">
                        登录
                    </Button>
                    </Form.Item>
                </Form>
                </div>
            </div>
        )
    }
}
const submitForm=Form.create()(Login)
export default submitForm